package com.stop.think.shiro.web.aop;

import cn.hutool.json.JSONObject;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@ControllerAdvice(annotations = {RestController.class, Controller.class})
public class EmpErrorAop {

    @ExceptionHandler({UnauthorizedException.class})
    @ResponseBody
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public String errorResponse(Exception e) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.set("errorMsg", "对不起，您没有此权限！");
        return jsonObject.toString();
    }
}
